package com.css.fxfzdpzs.modules.dzzh.controller;

import com.alibaba.fastjson.JSONObject;
import com.css.fxfzdpzs.base.response.RestResponse;
import com.css.fxfzdpzs.modules.dzzh.entity.first.*;
import com.css.fxfzdpzs.modules.dzzh.param.LargeScreenParam;
import com.css.fxfzdpzs.modules.dzzh.param.ZoneParam;
import com.css.fxfzdpzs.modules.dzzh.service.DzzhService;
import com.css.fxfzdpzs.modules.dzzh.vo.*;
import com.css.fxfzdpzs.modules.xczh.entity.second.XcSecondMapEntity;
import com.css.fxfzdpzs.util.PlatformObjectUtils;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * @author y1fan
 * @description     dzzh
 */
@RestController
@RequestMapping("/dzzh")
@Slf4j
public class DzzhController {

    @Resource
    private DzzhService dzzhService;

    /**
     * 地质灾害 （一级目录）全国已有地震地质灾害数量
     *
     * @return
     */
    @GetMapping("/getDisasterNum")
    public RestResponse getDisasterNum(String code) {
        RestResponse restResponse = null;
        JSONObject jsonObject = new JSONObject();
        try {
            if (PlatformObjectUtils.isEmpty(code)){
                code="0";
            }
            DzzhEarthquakeDisasterNum dzzhEarthquakeDisasterNum = dzzhService.getDisasterNum(code);
            jsonObject.put("message", "查询成功!");
            restResponse = RestResponse.succeed(dzzhEarthquakeDisasterNum);
        } catch (Exception e) {
            String errormessage = "查询失败";
            log.error(errormessage, e);
            restResponse = RestResponse.fail(errormessage);
        }
        return restResponse;
    }
    /**
     * 地质灾害 （一级目录）各省(直辖市)地震地质灾害发育数量图
     *
     * @return
     */
    @GetMapping("/getProvinceDisasterNum")
    public RestResponse getProvinceDisasterNum(String code) {
        RestResponse restResponse = null;
        JSONObject jsonObject = new JSONObject();
        try {
            List<DzzhProvinceDisasterNum> dzzhProvinceDisasterNum = dzzhService.getProvinceDisasterNum(code);
            jsonObject.put("message", "查询成功!");
            restResponse = RestResponse.succeed(dzzhProvinceDisasterNum);
        } catch (Exception e) {
            String errormessage = "查询失败";
            log.error(errormessage, e);
            restResponse = RestResponse.fail(errormessage);
        }
        return restResponse;
    }

    /**
     * 地质灾害 （一级目录）8.1.83地震地质灾害系统服务统计
     *
     * @return
     */
    @GetMapping("/getDisasterCount")
    public RestResponse getDisasterCount() {
        RestResponse restResponse = null;
        JSONObject jsonObject = new JSONObject();
        try {
            DzzhEarthquakeDisasterCountVO vo = dzzhService.getDisasterCount();
            jsonObject.put("message", "查询成功!");
            restResponse = RestResponse.succeed(vo);
        } catch (Exception e) {
            String errormessage = "查询失败";
            log.error(errormessage, e);
            restResponse = RestResponse.fail(errormessage);
        }
        return restResponse;
    }

    /**
     * 地质灾害 （一级目录）8.1.79危险性面积统计分析
     *
     * @return
     */
    @GetMapping("/getRiskAreaAnalysis")
    public RestResponse getRiskAreaAnalysis(String code) {
        RestResponse restResponse = null;
        JSONObject jsonObject = new JSONObject();
        try {
            if (PlatformObjectUtils.isEmpty(code)){
                code="0";
            }
            Map<String,List<DzzhRiskAreaAnalysis>> map = dzzhService.getRiskAreaAnalysis(code);
            jsonObject.put("message", "查询成功!");
            restResponse = RestResponse.succeed(map);
        } catch (Exception e) {
            String errormessage = "查询失败";
            log.error(errormessage, e);
            restResponse = RestResponse.fail(errormessage);
        }
        return restResponse;
    }

    //全国地震地质灾害概况
    @GetMapping("/getDisasterOverview")
    public RestResponse getDisasterOverview(String landslideSecondType,String sandSecondType,String weakSecondType,String code) {
        RestResponse restResponse = null;
        try {
            if (PlatformObjectUtils.isEmpty(code)){
                code="0";
            }
            DisasterRequestVO disasterRequestVO=new DisasterRequestVO(landslideSecondType,sandSecondType,weakSecondType);
            DisasterResponseVO vo= dzzhService.getDisasterOverview(disasterRequestVO,code);
            restResponse = RestResponse.succeed(vo);
        } catch (Exception e) {
            String errormessage = "查询全国地震地质灾害概况失败";
            log.error(errormessage, e);
            restResponse = RestResponse.fail(errormessage);
        }
        return restResponse;
    }

    /**
     * 地质灾害 （一级目录）地图
     *
     * @return
     */
    @GetMapping("/getMap")
    public RestResponse getMap(DzzhEvaluationTypeVO dzzhEvaluationTypeVO) {
        RestResponse restResponse = null;
        JSONObject jsonObject = new JSONObject();
        try {
            List<DzzhEvaluationType> dzzhEvaluationTypes = dzzhService.getMap(dzzhEvaluationTypeVO);
            jsonObject.put("message", "查询成功!");
            restResponse = RestResponse.succeed(dzzhEvaluationTypes);
        } catch (Exception e) {
            String errormessage = "查询失败";
            log.error(errormessage, e);
            restResponse = RestResponse.fail(errormessage);
        }
        return restResponse;
    }




    /**
     * 地质灾害 （一级目录）8.1.80.1全国地震地质灾害概况-地震滑坡
     *
     * @return
     */
    @GetMapping("/getOverviewLandslide")
    public RestResponse getOverviewLandslide() {
        RestResponse restResponse = null;
        JSONObject jsonObject = new JSONObject();
        try {
            List<DzzhEarthquakeOverviewLandslide> dzzhEarthquakeOverviewLandslides = dzzhService.getOverviewLandslide();
            jsonObject.put("message", "查询成功!");
            restResponse = RestResponse.succeed(dzzhEarthquakeOverviewLandslides);
        } catch (Exception e) {
            String errormessage = "查询失败";
            log.error(errormessage, e);
            restResponse = RestResponse.fail(errormessage);
        }
        return restResponse;
    }
    /**
     * 地质灾害 （一级目录）8.1.80.1全国地震地质灾害概况-地震滑坡
     *dzzh_earthquake_overview_liquefying
     * @return
     */
    @GetMapping("/getOverviewLiquefying")
    public RestResponse getOverviewLiquefying() {
        RestResponse restResponse = null;
        JSONObject jsonObject = new JSONObject();
        try {
            List<DzzhEarthquakeOverviewLiquefying> dzzhEarthquakeOverviewLiquefyings = dzzhService.getOverviewLiquefying();
            jsonObject.put("message", "查询成功!");
            restResponse = RestResponse.succeed(dzzhEarthquakeOverviewLiquefyings);
        } catch (Exception e) {
            String errormessage = "查询失败";
            log.error(errormessage, e);
            restResponse = RestResponse.fail(errormessage);
        }
        return restResponse;
    }
    /**
     * 地质灾害 （一级目录）8.1.80.1全国地震地质灾害概况-地震滑坡
     *dzzh_earthquake_overview_seismic_subsidence
     * @return
     */
    @GetMapping("/getOverviewSeismicSubsidence")
    public RestResponse getOverviewSeismicSubsidence() {
        RestResponse restResponse = null;
        JSONObject jsonObject = new JSONObject();
        try {
            List<DzzhEarthquakeOverviewSeismicSubsidence> dzzhEarthquakeOverviewSeismicSubsidences = dzzhService.getOverviewSeismicSubsidence();
            jsonObject.put("message", "查询成功!");
            restResponse = RestResponse.succeed(dzzhEarthquakeOverviewSeismicSubsidences);
        } catch (Exception e) {
            String errormessage = "查询失败";
            log.error(errormessage, e);
            restResponse = RestResponse.fail(errormessage);
        }
        return restResponse;
    }
    /**
     * 地质灾害 （一级目录）8.1.80.1全国地震地质灾害概况-地震滑坡
     *dzzh_earthquake_overview_seismic_subsidence
     * @return
     */
    @GetMapping("/getOverviewBreak")
    public RestResponse getOverviewBreak() {
        RestResponse restResponse = null;
        JSONObject jsonObject = new JSONObject();
        try {
            List<DzzhEarthquakeOverviewSeismicSubsidence> dzzhEarthquakeOverviewSeismicSubsidences = dzzhService.getOverviewBreak();
            jsonObject.put("message", "查询成功!");
            restResponse = RestResponse.succeed(dzzhEarthquakeOverviewSeismicSubsidences);
        } catch (Exception e) {
            String errormessage = "查询失败";
            log.error(errormessage, e);
            restResponse = RestResponse.fail(errormessage);
        }
        return restResponse;
    }

    /**
     * 地质灾害 （一级目录）获取根据灾害数量在地图上显示
     *dzzh_earthquake_overview_seismic_subsidence
     * @return
     */
    @GetMapping("/getMapDisaster")
    public RestResponse getMapDisaster(String type, @RequestParam(required = false) String code) {
        RestResponse restResponse = null;
        JSONObject jsonObject = new JSONObject();
        try {
            DzzhEarthquakeDisasterNum mapDisaster = dzzhService.getMapDisaster(type, code);
            jsonObject.put("message", "查询成功!");
            restResponse = RestResponse.succeed(mapDisaster);
        } catch (Exception e) {
            String errormessage = "查询失败";
            log.error(errormessage, e);
            restResponse = RestResponse.fail(errormessage);
        }
        return restResponse;
    }

    //全国地震灾害损失 地图数据   逻辑斯蒂模型数据
    @GetMapping("/getResultLogisticGrowth")
    public RestResponse getResultLogisticGrowth(String dzIntensity) {
        RestResponse restResponse = null;
        try {
            List<LogisticGrowthEntity> list=dzzhService.getResultLogisticGrowth(dzIntensity);
            restResponse = RestResponse.succeed(list);
        } catch (Exception e) {
            String errormessage = "查询失败";
            log.error(errormessage, e);
            restResponse = RestResponse.fail(errormessage);
        }
        return restResponse;
    }
    //全国地震灾害损失 地图数据   地震滑坡
    @GetMapping("/getSeismicLandslide")
    public RestResponse getSeismicLandslide(String type,String dzIntensity,String code) {
        RestResponse restResponse = null;
        try {
            List<SeimicLandslideEntity> list=dzzhService.getSeismicLandslide(type,dzIntensity,code);
            restResponse = RestResponse.succeed(list);
        } catch (Exception e) {
            String errormessage = "查询失败";
            log.error(errormessage, e);
            restResponse = RestResponse.fail(errormessage);
        }
        return restResponse;
    }

    //全国地震灾害损失 地图数据   砂土液化
    @GetMapping("/getSandLiquefaction")
    public RestResponse getSandLiquefaction(String type,String dzIntensity,String code) {
        RestResponse restResponse = null;
        try {
            List<SeimicLandslideEntity> list=dzzhService.getSandLiquefaction(type,dzIntensity,code);
            restResponse = RestResponse.succeed(list);
        } catch (Exception e) {
            String errormessage = "查询失败";
            log.error(errormessage, e);
            restResponse = RestResponse.fail(errormessage);
        }
        return restResponse;
    }

    //全国地震灾害损失 地图数据   软土震陷
    @GetMapping("/getSoftEarth")
    public RestResponse getSoftEarth(String type,String dzIntensity,String code) {
        RestResponse restResponse = null;
        try {
            List<SeimicLandslideEntity> list=dzzhService.getSoftEarth(type,dzIntensity,code);
            restResponse = RestResponse.succeed(list);
        } catch (Exception e) {
            String errormessage = "查询失败";
            log.error(errormessage, e);
            restResponse = RestResponse.fail(errormessage);
        }
        return restResponse;
    }

    /**
     * 一二级页面通用   三种评估统计
     * @param param
     * @return
     */
    @PostMapping("getByEstimate")
    public RestResponse getByEstimate(@RequestBody HashMap<String,Object> param) {
        RestResponse restResponse = null;
        try {
            Map<String, Object> map =dzzhService.getByEstimate(param);
            restResponse = RestResponse.succeed(map);
        } catch (Exception e) {
            String errormessage = "查询失败";
            log.error(errormessage, e);
            restResponse = RestResponse.fail(errormessage);
        }
        return restResponse;
    }

    /**
     * 地表破裂带
     * @param param
     * @return
     */
    @GetMapping("getSurfaceRuptureZone")
    public RestResponse getSurfaceRuptureZone(ZoneParam param) {
        RestResponse restResponse = null;
        try {
            List<SurfaceRuptureZoneVo> list = dzzhService.getSurfaceRuptureZone(param);
            restResponse = RestResponse.succeed(list);
        } catch (Exception e) {
            String errormessage = "查询失败";
            log.error(errormessage, e);
            restResponse = RestResponse.fail(errormessage);
        }
        return restResponse;
    }
}
